package com.hluck.goodweatherapp.data.repository;

import androidx.lifecycle.MutableLiveData;

import com.hluck.goodweatherapp.data.bean.BingResponse;
import com.hluck.goodweatherapp.data.network.api.ApiService;
import com.hluck.goodweatherapp.utils.LogUtils;
import com.hluck.mvvmlibrary.network.ApiType;
import com.hluck.mvvmlibrary.network.NetworkApi;
import com.hluck.mvvmlibrary.network.observer.BaseObserver;

/**
 * @Author： LJH
 * @Time： 2024/1/5
 * @description：
 */
public class BingRepository {

    private BingRepository() {
    }

    private static final class BingRepositoryHolder{
        private static final BingRepository mInstance = new BingRepository();
    }

    public static BingRepository getInstance(){
        return BingRepositoryHolder.mInstance;
    }

    public void bing(MutableLiveData<BingResponse> responseLiveDate,MutableLiveData<String> failed){
        String type = "必应壁纸-->";

        NetworkApi.createService(ApiService.class, ApiType.BING).bing()
                .compose(NetworkApi.applySchedulers(new BaseObserver<BingResponse>() {
                    @Override
                    public void onSuccess(BingResponse bingResponse) {
                        if (bingResponse == null) {
                            failed.postValue("必应壁纸数据为null。");
                            return;
                        }
                        LogUtils.logD("BingResponse:"+bingResponse.getImages().size());
                        responseLiveDate.postValue(bingResponse);
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        LogUtils.logE("onFailure"+e.getMessage());
                    }
                }));
    }
}
